/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package XOrules;

import java.util.*;
import java.lang.*;
import java.math.*;
import common.*;


public class GameManager extends XOrules.KA{

    public final static String GM_0 = "0";

    public boolean isClient;

    public GameManager(){
	sendMsg("newGame");
    }

    private Request _doRequest(Request req){
	if (client != null) {
	    Object res = Evaluator.callMethod(this, "pre_" + req.type, req); //null; //eval("this.pre_" + req.type)(req);
	    if (res != null){
		return req.Answer(this, false, res);
	    }
        }

	if (client != null){
	    Object res = Evaluator.callMethod(this, "pre_" + req.type, req);
	}

	return req.Answer(this, true);
    }
    public void doState(Object exitValue_){
    }

    public void exit(){
    }

    public void stopGame() {
	super.setState(this, GM_0);
    }

    public void sendMsg(String[] msg){
	for(String usr : data.gamers){
	    HashMap<String, String> msg_to_send = new HashMap<String, String>();
	    msg_to_send.put(MSG_USR, name);
	    msg_to_send.put(MSG_TYPE, "sendMsg");
	    msg_to_send.put(MSG_BODY, json.dumps(usr, msg));
	    bgtp_mail(msg_to_send);
	}
    }


    public void sendRequest(req){
	String[] tmp = new String[3];
	tmp[0]	     = req.usr;
	tmp[1]	     = req.type;
	tmp[2]	     = json.dumps(req.body);

	sendMsg(tmp);
    }

    //#interface for server
    public boolean setSituation(situation_){
	return true;
	//TODO with json
    }

    public String getSituation(forWhom){
	return "";
	//TODO with json
    }
}
